#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/types.h>

int main()
{
    int fd[2] = {0};
    if (pipe(fd) < 0)
    {
        perror("pipe");
        return 1;
    }
    pid_t id = fork();
    if (id == 0)
    {
        //child read
        close(fd[1]);
        char buff[64];
        ssize_t s = read(fd[0],buff,sizeof(buff));
        buff[s] = '\n';
        printf("%s\n",buff);
    }
    // father write
    close(fd[0]);
    const char *msg = "i am father\n";
    write(fd[1], msg, strlen(msg));

    close(fd[1]);
    waitpid(id, NULL, 0);

    return 0;
}